package com.jiang.test;

import java.io.IOException;
import java.io.Reader;
import java.util.Date;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.jiang.vo.News;

public class FirstMyBatisDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// MyBatis使用的是Reader类，所以使用Resources类获取
		try {
			Reader reader = Resources.getResourceAsReader("mybatis.cfg.xml");
			// 获取SqlSessionFactory
			SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(reader);
			SqlSession session = sf.openSession();
			News news = new News();
			news.setTitle("测试好");
			news.setPubdate(new Date());
			news.setContent("我是测试的内容");
			session.insert("com.jiang.vo.mapping.newsNS.doCreate", news);
			// 注意一定要提交
			session.commit();
			session.close();
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}
